/*  yALB - Yet Another List Builder (roster Editor for Wargames/tabletop games).
    Copyright (C) 2008-2012  Daniel Ricardo Castro Alvarado

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.*/

#ifndef STRUCTREADER_H
#define STRUCTREADER_H

#include <QXmlStreamReader>

#include "other/gameStructs.h"
#include "other/unit.h"

class GameFileStructs;
class ArmyFileStructs;

class StructReader : public QObject
{
    Q_OBJECT
public:
    enum ReadResult {
        FileAccessError = 0,
        IncompatibleGameFile,
        IncompatibleArmyFile,
        Success
    };

    StructReader(QXmlStreamReader& reader);
    FileInformation readFileInformation();
    GameCategory readUnitCategory(QString& key);
    GameCategory readItemCategory(QString& key);
    GameCategory readOptionCategory(QString& key);
    Column readColumn(QString& key);
    GameProperty readUnitProperty(QString& key);
    GameProperty readItemProperty(QString& key);
    GameProperty readOptionProperty(QString& key);
    QHash<QString, QString> readProperties();
    Actions readActions();
    UnitOption readOption(QString& key, QString& inherits);
    GameItem readItem(QString& key);
    QHash<QString, QString> readCells();
    QHash<QString, InheritedCategoryData> readItemLimits();
    Unit readUnit(QString& key, QHash<QString, QHash<QString, QString> > *inheritedOptions = 0);
    GlobalText readGlobalText(QString& key);
    CategoryDataHash readInheritedUnitCategoryData();
    CategoryDataHash readInheritedItemCategoryData();
    CategoryDataHash readInheritedOptionCategoryData();
    QHash<QString, InheritedItemData> readInheritedItemData();
    QHash<QString, InheritedOptionData> readInheritedOptionData();


    static bool isValidGameFile(QXmlStreamReader &reader);
    static bool isValidGameFile(const QString& fileName);
    static bool isValidArmyFile(QXmlStreamReader &reader);
    static bool isValidArmyFile(const QString& fileName);
    static ReadResult readGameFile(GameFileStructs& fileStructs, FileInformation &information,
                                   const QString& fileName, QWidget* parent = 0, bool removeAll = true);
    static ReadResult readArmyFile(ArmyFileStructs& fileStructs, FileInformation &armyInformation,
                                   const QString& armyFile, QWidget* parent = 0,
                                   QHash<QString, QHash<QString, QString> > *inheritedOptions = 0,
                                   bool removeAll = true);

private:
    QXmlStreamReader *reader;
};

#endif // STRUCTREADER_H
